1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67
| public class demo1 { List<Employee> emps = Arrays.asList( new Employee(102, "李四", 79, 6666.66, Employee.Status.BUSY), new Employee(101, "张三", 18, 9999.99, Employee.Status.FREE), new Employee(103, "王五", 28, 3333.33, Employee.Status.VOCATION), new Employee(104, "赵六", 8, 7777.77, Employee.Status.BUSY), new Employee(104, "赵六", 8, 7777.77, Employee.Status.FREE), new Employee(104, "赵六", 8, 7777.77, Employee.Status.FREE), new Employee(105, "田七", 38, 5555.55, Employee.Status.BUSY) );
public static void main(String[] args) { }
@Test public void test1() { List<String> list = Arrays.asList("ccc", "aaa", "bbb"); list.stream().sorted().forEach(System.out::println); }
@Test public void test12() { boolean b1 = emps.stream().allMatch((e) -> e.getStatus().equals(Employee.Status.BUSY)); System.out.print(b1);
boolean b2 = emps.stream().anyMatch((e) -> e.getStatus().equals(Employee.Status.BUSY)); System.out.print(b2);
boolean b3 = emps.stream().noneMatch((e) -> e.getStatus().equals(Employee.Status.BUSY)); System.out.print(b3); Optional<Employee> first = emps.stream().sorted((e1, e2) -> Double.compare(e1.getSalary(), e2.getSalary())).findFirst(); System.out.println(first.get());
Optional<Employee> op2 = emps.stream().filter((e) -> e.getStatus().equals(Employee.Status.BUSY)) .findAny();
System.out.println(op2.get()); }
@Test public void test2() {
long count = emps.stream().count();
System.out.println(count);
Optional<Employee> max = emps.stream().max((e1, e2) -> Double.compare(e1.getSalary(), e2.getSalary())); System.out.println(max.get());
Optional<Double> min = emps.stream().map((Employee::getSalary)).min(Double::compare); System.out.println(min.get());
}
|